<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/5/14
  Time: 10:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="jquery-3.6.0.min.js"></script>
</head>
<body>
    用户名:<input id="inp" type="text" name="uname" value="">
    <span id="s1"></span>
</body>
</html>
<script>
    $("#inp").blur(function() {
        var uname = $(this).val();
        if(uname == null || uname == "") {
          $("#s1").text("不能为空");
          $("#s1").css("color","red");
          return;
        }

        //AJAX请求
        $.post("homework01Servlet",
            {"mark":"unameIsUnique","uname":uname},
            function(obj) {
            ////i > 0 true 查询的到  不让注册     i = 0 false 查不到  让注册
                if(obj) {
                    $("#s1").text("已存在");
                    $("#s1").css("color","red");
                }else {
                    $("#s1").text("可以注册");
                    $("#s1").css("color","green");
                }

        },"json");

    });
</script>
